package org.xm.sk;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

import org.junit.Test;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class SkApplicationTests3 {

    @Test
    public void test() throws Exception {
        String deallineStr = "2018-03-20 23:36:50";
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date dealline = sdf.parse(sdf.format(sdf2.parse(deallineStr)));
        Date now = sdf.parse(sdf.format(new Date()));
        if (dealline.getTime() < now.getTime())
            log.info("优惠券所属活动已截至");
        getRandomNumCode(4);
    }

    public static String getRandomNumCode(int number) {
        String codeNum = "";
        int[] numbers = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
        Random random = new Random();
        for (int i = 0; i < number; i++) {
            int next = random.nextInt(100000);// 目的是产生足够随机的数，避免产生的数字重复率高的问题
            // System.out.println(next);
            codeNum += numbers[next % 10];
        }
        System.out.println("--------");
        System.out.println(codeNum);

        return codeNum;
    }

}
